﻿#define _CRT_SECURE_NO_WARNINGS//模拟实现strstr
#include<stdio.h>
#include<string.h>
char* my_strstr(char* str1, char* str2)
{
	const char* s1 = str1;
	const char* s2 = str2;
	const char* p = str1;
	if (*str2 == '\0')
	{
		return str1;
	}
	while (*p)
	{
		s1 = p;
		s2 = str2;
		while (*s1 != '\0' && *s2 != '\0' && (*s1 == *s2))
		{
			s1++;
			s2++;
		}
		if (*s2 == '\0')
		{
			return (char*)p;//找到了
		}
		p++;
	}
	return NULL;//找不到子串

}
int main()
{
	char arr1[] = "abccdef";
	char arr2[] = "cd";
	char* p = strstr(arr1, arr2);
	printf("%s\n", p);
	char* pp = my_strstr(arr1, arr2);
	printf("%s\n", pp);
	return 0;
}